package com.boilerCloud.service.sys.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.boilerCloud.dao.sys.IHzlqswUserDao;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.account.AccountLoginRecordBean;
import com.boilerCloud.dto.account.LoginAccountBean;
import com.boilerCloud.dto.sys.User;
import com.boilerCloud.service.sys.IHzlqswUserService;
import com.boilerCloud.util.MD5;


@Service
public class HzlqswUserServiceImpl implements IHzlqswUserService {

	@Resource
	private IHzlqswUserDao userDao;

	/**
	 * 校验用户账号和密码
	 * 
	 * @param account
	 * @param pwd
	 * @return
	 * @throws Exception
	 */
	public boolean checkUser(String account, String pwd) throws Exception {
		return userDao.checkUser(account, pwd);
	}

	
	/**
	 * @函数功能说明:根据帐号获取用户信息
	 * @创建者：qianfuqiang 2013-8-9
	 * @修改者：
	 * @修改内容：
	 * @参数： @param account
	 * @参数： @return
	 * @参数： @throws Exception
	 * @返回： User
	 * @抛出异常：
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public User getUserInfoByAccount(String account) throws Exception {
		User user =  userDao.getUserInfoByAccount(account);
		
		return user;
	}


	@Override
	public void qryList(User account,
			HzlqswPage<User> page) throws Exception {
		userDao.qryList(account,page);
		
	}


	@Override
	public int resetPassword(int id) throws Exception {
		// TODO Auto-generated method stub
		return userDao.resetPassword(id,MD5.getMD5("666666"));
	}


	@Override
	public int delAccount(int id) throws Exception {
		// TODO Auto-generated method stub
		return userDao.delAccount(id);
		
	}


	@Override
	public boolean save(User user) throws Exception {
		User userDto =  userDao.getUserInfoByAccount(user.getAccount());
		if(userDto != null)return false;
		user.setPwd(MD5.getMD5(user.getPwd()));
		userDao.addUser(user);
		return true;
		
	}


	@Override
	public void edit(User user) throws Exception {
		userDao.editUser(user);
		
	}


	@Override
	public User getUserByid(int id) throws Exception {
		// TODO Auto-generated method stub
		return userDao.getUserByid(id);
	}




	
}
